package com.kukudexin.base01;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author: 酷酷的鑫
 * @description:
 */
public class Thread02 {
    /**
     * 注意 这里使用feature 和callable 使得thread-0 与main 线程由异步变成同步。
     * 主线程必须等待thread0的返回结果
     * @param args
     * @throws ExecutionException
     * @throws InterruptedException
     */
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadCallable threadCallable = new ThreadCallable();
        FutureTask<Integer> integerFutureTask = new FutureTask<>(threadCallable);
        new Thread(integerFutureTask).start();
        Integer result = integerFutureTask.get();
        System.out.println(result);
        System.out.println(Thread.currentThread().getName() + ",");
    }
}
